package impl

import (
	"context"
	"gitee.com/kevin186/keyauth/apps/menu"
	"github.com/infraboard/mcube/exception"
)

func (s *service) CreateMenuRole(ctx context.Context, req *menu.CreateMenuRequest) (*menu.MenuRole, error) {
	//if err := req.Validate(); err != nil {
	//	return nil, exception.NewBadRequest("validate create user error, %s", err)
	//}

	ins, err := menu.NewMenuRole(req)
	if err != nil {
		return nil, err
	}

	// s.col.InsertMany()
	if _, err := s.col.InsertOne(ctx, ins); err != nil {
		return nil, exception.NewInternalServerError("inserted menu(%s) document error, %s",
			ins.UserName, err)
	}
	return ins, nil
}

func (s *service) DescribeMenuRole(ctx context.Context, req *menu.DescribeRoleRequest) (*menu.MenuRole, error) {
	return s.get(ctx, req)
}
